import { ResultStatus } from './result';
import { Result } from './result.dto';

export class ResponseFactory {
  static success<T>(data?: T, message = '操作成功'): Result<T> {
    return new Result(ResultStatus.SUCCESS, 200, message, data);
  }

  static error<T>(message = '操作失败', code = 500, data?: T): Result<T> {
    return new Result(ResultStatus.ERROR, code, message, data);
  }

  static warning<T>(message: string, code = 400, data?: T): Result<T> {
    return new Result(ResultStatus.WARNING, code, message, data);
  }

  static info<T>(message: string, code = 200, data?: T): Result<T> {
    return new Result(ResultStatus.INFO, code, message, data);
  }

  static unauthorized<T>(message = '未授权', data?: T): Result<T> {
    return new Result(ResultStatus.ERROR, 401, message, data);
  }

  static forbidden<T>(message = '禁止访问', data?: T): Result<T> {
    return new Result(ResultStatus.ERROR, 403, message, data);
  }

  static notFound<T>(message = '资源未找到', data?: T): Result<T> {
    return new Result(ResultStatus.ERROR, 404, message, data);
  }
}
